//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "InflationIndex.h"
using namespace Cephei::QL::Indexes;
#include <gen/QL/Times/Period.h>
#include <gen/QL/Currency.h>
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Indexes/Region.h>
#include <gen/QL/Index.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL;
#define HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Indexes::CInflationIndex::CInflationIndex (boost::shared_ptr<QuantLib::InflationIndex>& childNative, Object^ owner) : CIndex(CInflationIndex::typeid)
{
#ifdef HANDLE
	_phInflationIndex = NULL;
#endif
	_ppInflationIndex = &childNative;
    _ppIndex = new boost::shared_ptr<QuantLib::Index> (boost::dynamic_pointer_cast<QuantLib::Index> (*_ppInflationIndex));
}
Cephei::QL::Indexes::CInflationIndex::CInflationIndex (QuantLib::InflationIndex& childNative, Object^ owner) : CIndex(CInflationIndex::typeid)
{
#ifdef HANDLE
	_phInflationIndex = NULL;
#endif
	_ppInflationIndex = new boost::shared_ptr<QuantLib::InflationIndex> (&childNative);
    _ppIndex = new boost::shared_ptr<QuantLib::Index> (boost::dynamic_pointer_cast<QuantLib::Index> (*_ppInflationIndex));
    _InflationIndexOwner = owner;
    _IndexOwner = owner;
}

Cephei::QL::Indexes::CInflationIndex::CInflationIndex (CInflationIndex^ copy) : CIndex(CInflationIndex::typeid)
{
#ifdef HANDLE
	_phInflationIndex = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppInflationIndex = new boost::shared_ptr<QuantLib::InflationIndex> (copy->GetShared());
        _ppIndex = new boost::shared_ptr<QuantLib::Index> (boost::dynamic_pointer_cast<QuantLib::Index> (*_ppInflationIndex));
    }
}
Cephei::QL::Indexes::CInflationIndex::CInflationIndex (PLATFORM::Type^ t) : CIndex(CInflationIndex::typeid)
{
#ifdef HANDLE
	_phInflationIndex = NULL;
#endif
	if (!t->IsSubclassOf(CInflationIndex::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Indexes::CInflationIndex::CInflationIndex (QuantLib::Handle<QuantLib::InflationIndex>& childNative, Object^ owner)  : CIndex(CInflationIndex::typeid)
{
	_phInflationIndex = &childNative;
	_ppInflationIndex = &static_cast<boost::shared_ptr<QuantLib::InflationIndex>>(childNative.currentLink());
    _ppIndex = new boost::shared_ptr<QuantLib::Index> (boost::dynamic_pointer_cast<QuantLib::Index> (*_ppInflationIndex));
    _InflationIndexOwner = owner;
}
Cephei::QL::Indexes::CInflationIndex::CInflationIndex (QuantLib::Handle<QuantLib::InflationIndex> childNative)  : CIndex(CInflationIndex::typeid)
{
	_phInflationIndex = &childNative;
	_ppInflationIndex = &static_cast<boost::shared_ptr<QuantLib::InflationIndex>>(childNative.currentLink());
    _ppIndex = new boost::shared_ptr<QuantLib::Index> (boost::dynamic_pointer_cast<QuantLib::Index> (*_ppInflationIndex));
}
#endif
#ifdef STRUCT
Cephei::QL::Indexes::CInflationIndex::CInflationIndex (QuantLib::InflationIndex childNative)  : CIndex(CInflationIndex::typeid)
{
#ifdef HANDLE
	_phInflationIndex = NULL;
#endif
	_ppInflationIndex = new boost::shared_ptr<QuantLib::InflationIndex> (new QuantLib::InflationIndex (childNative));
    _ppIndex = new boost::shared_ptr<QuantLib::Index> (boost::dynamic_pointer_cast<QuantLib::Index> (*_ppInflationIndex));
}
#endif

Cephei::QL::Indexes::CInflationIndex::~CInflationIndex ()
{
    if (_ppInflationIndex != NULL)
    {
	    delete _ppInflationIndex;
        _ppInflationIndex = NULL;
    }
}
Cephei::QL::Indexes::CInflationIndex::!CInflationIndex ()
{
    if (_ppInflationIndex != NULL)
    {
	    delete _ppInflationIndex;
    }
}
QuantLib::InflationIndex& Cephei::QL::Indexes::CInflationIndex::GetReference ()
{
    if (_ppInflationIndex == NULL) throw REFNEW NativeNullException ();
	return **_ppInflationIndex;
}
boost::shared_ptr<QuantLib::InflationIndex>& Cephei::QL::Indexes::CInflationIndex::GetShared ()
{
    if (_ppInflationIndex == NULL) throw REFNEW NativeNullException ();
	return *_ppInflationIndex;
}
QuantLib::InflationIndex* Cephei::QL::Indexes::CInflationIndex::GetPointer ()
{
    if (_ppInflationIndex == NULL) throw REFNEW NativeNullException ();
	return &**_ppInflationIndex;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::InflationIndex>& Cephei::QL::Indexes::CInflationIndex::GetHandle ()
{
	if (_phInflationIndex == NULL)
	{
		_phInflationIndex = new Handle<QuantLib::InflationIndex> (*_ppInflationIndex);
	}
	return *_phInflationIndex;
}
#endif
bool Cephei::QL::Indexes::CInflationIndex::HasNative () 
{
	return (_ppInflationIndex != NULL);
}

Cephei::QL::Indexes::IInflationIndex^ Cephei::QL::Indexes::CInflationIndex::AddFixing (DateTime fixingDate, Double fixing, Microsoft::FSharp::Core::FSharpOption<Boolean>^ forceOverwrite)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Date _fixingDate = (QuantLib::Date)ValueHelper::Convert (fixingDate); //a
        QuantLib::Rate _fixing = (QuantLib::Rate)ValueHelper::Convert (fixing); //a
        bool _forceOverwrite = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (forceOverwrite) ? (bool)ValueHelper::Convert (forceOverwrite->Value) : false); //9a
    	(*_ppInflationIndex)->addFixing ( _fixingDate,  _fixing,  _forceOverwrite );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::IPeriod^ Cephei::QL::Indexes::CInflationIndex::AvailabilityLag::get ()
{
    try
    {
    	QuantLib::Period _rv = (QuantLib::Period)(*_ppInflationIndex)->availabilityLag ( );   
        Cephei::QL::Times::CPeriod^ _nrv = REFNEW Cephei::QL::Times::CPeriod (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::ICurrency^ Cephei::QL::Indexes::CInflationIndex::Currency::get ()
{
    try
    {
    	QuantLib::Currency _rv = (QuantLib::Currency)(*_ppInflationIndex)->currency ( );   
        Cephei::QL::CCurrency^ _nrv = REFNEW Cephei::QL::CCurrency (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
String^ Cephei::QL::Indexes::CInflationIndex::FamilyName::get ()
{
    try
    {
    	std::string _rv = (std::string)(*_ppInflationIndex)->familyName ( );   
        String^ _nrv = (String^)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::ICalendar^ Cephei::QL::Indexes::CInflationIndex::FixingCalendar::get ()
{
    try
    {
    	QuantLib::Calendar _rv = (QuantLib::Calendar)(*_ppInflationIndex)->fixingCalendar ( );   
        Cephei::QL::Times::CCalendar^ _nrv = REFNEW Cephei::QL::Times::CCalendar (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
QL::Times::FrequencyEnum Cephei::QL::Indexes::CInflationIndex::Frequency::get ()
{
    try
    {
    	QuantLib::Frequency _rv = (QuantLib::Frequency)(*_ppInflationIndex)->frequency ( );   
        QL::Times::FrequencyEnum _nrv = (QL::Times::FrequencyEnum)_rv;
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Indexes::CInflationIndex::Interpolated::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppInflationIndex)->interpolated ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Indexes::CInflationIndex::IsValidFixingDate (DateTime fixingDate)
{
    try
    {
        QuantLib::Date _fixingDate = (QuantLib::Date)ValueHelper::Convert (fixingDate); //a
    	bool _rv = (bool)(*_ppInflationIndex)->isValidFixingDate ( _fixingDate );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
String^ Cephei::QL::Indexes::CInflationIndex::Name::get ()
{
    try
    {
    	std::string _rv = (std::string)(*_ppInflationIndex)->name ( );   
        String^ _nrv = (String^)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Indexes::IRegion^ Cephei::QL::Indexes::CInflationIndex::Region::get ()
{
    try
    {
    	QuantLib::Region _rv = (QuantLib::Region)(*_ppInflationIndex)->region ( );   
        Cephei::QL::Indexes::CRegion^ _nrv = REFNEW Cephei::QL::Indexes::CRegion (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Indexes::CInflationIndex::Revised::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppInflationIndex)->revised ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Indexes::IInflationIndex^ Cephei::QL::Indexes::CInflationIndex::Update::get ()
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
    	(*_ppInflationIndex)->update ( );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

